package listing;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.testng.*;
import org.testng.annotations.*;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

import java.util.Random;

	public class Newsletter_positive extends ru.st.selenium.pages.TestBase {
	  private boolean acceptNextAlert = true;
	  private StringBuffer verificationErrors = new StringBuffer();
	 

	    @Test
	  public void testUntitled7() throws Exception {
	    	
	    	 Random rand = new Random();

	         String AlphabetString = "ABCDEFGHIKLMNOPQRSTVXYZabcdefghiklmnopqrstvxyz";

	         char [] alphabet = AlphabetString.toCharArray();
	         
	         StringBuilder generator = new StringBuilder(); 

	         for(int i = 0; i < 7; i++){
	         	generator.append(alphabet[rand.nextInt(alphabet.length)]);
	            
	         }
	         String email = generator.toString();
	    	
	    driver.get(baseUrl + "furniture.html");
	    driver.findElement(By.id("newsletter")).clear();
	    driver.findElement(By.id("newsletter")).sendKeys(email+"@"+email+".com");
	    driver.findElement(By.cssSelector("div.block-content > div.actions > button.button")).click();
	    try {
	      assertEquals("Thank you for your subscription.", driver.findElement(By.cssSelector("li.success-msg > ul > li > span")).getText());
	    } catch (Error e) {
	      verificationErrors.append(e.toString());
	    }
	  }

	   private boolean isElementPresent(By by) {
	    try {
	      driver.findElement(by);
	      return true;
	    } catch (NoSuchElementException e) {
	      return false;
	    }
	  }

	  
	  private String closeAlertAndGetItsText() {
	    try {
	      Alert alert = driver.switchTo().alert();
	      String alertText = alert.getText();
	      if (acceptNextAlert) {
	        alert.accept();
	      } else {
	        alert.dismiss();
	      }
	      return alertText;
	    } finally {
	      acceptNextAlert = true;
	    }
	  }
	}

